<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends Admin_Controller {

    private $uid;
	function __construct ()
	{
		parent::__construct();
		$this->load->model('user_m');
		$this->load->model('logs_m');
        $this->load->library('pagination');
		$this->load->library('form_validation');
        $this->uid = $this->session->userdata('user_id');
	}
	
	public function index($page=1)
	{
		$data['title'] = '默认首页';
		$data['siderbar'] = 'home';
		$data['submenu'] = 'home';
		
		// 查询日志
        $limit = 20;
        $config['uri_segment'] = 4;
        $config['use_page_numbers'] = TRUE;
        if($this->auth->is_super_admin()){
            $config['total_rows'] = $this->db->count_all('logs');
        }else{
            $config['total_rows'] = $this->db->where("user_id",$this->uid)->count_all('logs');
        }
        $config['base_url'] = site_url('manage/home/index/');
        $config['per_page'] = $limit;
        $config['num_links'] = 10;
        $start = ($page-1)*$limit;
        $this->pagination->initialize($config);
        $data['pagination'] = $this->pagination->create_links();
        if($this->auth->is_super_admin()){
            $logs = $this->logs_m->get_all_logs($start,$limit);
        }else{
            $logs = $this->logs_m->get_all_logs($start,$limit,$this->uid);
        }
        $data["logs"] = $logs;
		$this->load->view('index/home', $data);
	}
}